package com.kzd.sdk.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.kzd.sdk.callback.KZD_OnSmallListener;
import com.kzd.sdk.utils.AppUtils;

public class KZD_SmallAccountDialog extends Dialog {

    private KZD_OnSmallListener mOnClickListener;

    private EditText etSmallAccountName;

    public KZD_SmallAccountDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(AppUtils.getLayoutId(getContext(), "kzd_dialog_small_account"));
        initView();
    }

    @Override
    protected void onStart() {
        super.onStart();
        getWindow().getDecorView()
                .setBackgroundColor(Color.TRANSPARENT);
        etSmallAccountName.setText(null);
    }


    private void initView() {
        etSmallAccountName = findViewById(AppUtils.getId(getContext(), "etSmallAccountName"));
        //取消关闭对话框
        findViewById(AppUtils.getId(getContext(), "tvSmallAccountCancel"))
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        cancel();
                    }
                });
        //确认 回调
        findViewById(AppUtils.getId(getContext(), "tvSmallAccountConfirm"))
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Editable editable = etSmallAccountName.getText();
                        if (TextUtils.isEmpty(editable)) {
                            Toast.makeText(getContext(),"请输入小号名称",Toast.LENGTH_SHORT).show();
                            return;
                        }
                        if (mOnClickListener == null) {
                            return;
                        }
                        mOnClickListener.onName(editable.toString());
                    }
                });
    }

    public void setOnClickListener(KZD_OnSmallListener listener) {
        this.mOnClickListener = listener;
    }
}
